home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / s0ftpj / fbsdnospoof.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-17  |  3.5 KB  |  164 lines

  1. /*
  2.  * Name: ANTi SP00FiNG VIA SETSOCKOPT() ( fbsdnospoof.c )
  3.  * Date: Fri Feb 18 14:45:01 2000
  4.  * Author: pIGpEN [pigpen@s0ftpj.org, deadhead@sikurezza.org]
  5.  *
  6.  * SoftProject Digital Security for Y2K (www.s0ftpj.org)
  7.  * Sikurezza.org Italian Security MailingList (www.sikurezza.org)
  8.  * 
  9.  * COFFEE-WARE LICENSE - This source code is like "THE BEER-WARE LICENSE" by
  10.  * Poul-Henning Kamp <phk@FreeBSD.ORG> but you can give me in return a coffee.
  11.  * 
  12.  * Tested on: FreeBSD 4.0-19990705-CURRENT FreeBSD 4.0-19990705-CURRENT #6 i386
  13.  *          FreeBSD 3.4-RELEASE FreeBSD 3.4-RELEASE #0: Tue Dec i386
  14.  *
  15.  * Thanks to: del0rean / s0ftPj for cd with 3.4 release 
  16.  *            Lynyrd Skynyrd for Sweet Home Alabama
  17.  *
  18.  * Use a kld Makefile.. ( put in append ) 
  19.  */
  20.  
  21. /*
  22.  * This kld detects type of ip spoofing based on setsockopt()... with IP_HDRINCL
  23.  * It works monitoring setsockopt() system call 
  24.  *
  25.  * example of detection:
  26.  *
  27.  * ./DoS -s 666.666.666.666 -d 192.168.1.4
  28.  * IP_HDRINCL: Invalid argument
  29.  *
  30.  * syslog:
  31.  *
  32.  * Feb 18 14:44:25 storpio /kernel: Detect IP_HDRINCL invoked by d0s
  33.  * Feb 18 14:44:25 storpio /kernel: IP header manipulation... DENIED!
  34.  *
  35.  */
  36.  
  37. /*
  38.  * Define DONT_PERMIT    ->    if you want to forbid IP header manipulation
  39.  *                 and so the chance of IP Spoofing from your
  40.  *                 BOX
  41.  */
  42.  
  43. #define DONT_PERMIT
  44.  
  45. #include <sys/types.h>
  46. #include <sys/param.h>
  47. #include <sys/proc.h>
  48. #include <sys/module.h>
  49. #include <sys/syscall.h>
  50. #include <sys/sysent.h> 
  51. #include <sys/kernel.h>
  52. #include <sys/systm.h>
  53. #include <sys/sysproto.h>
  54. #include <sys/socket.h>
  55. #include <sys/socketvar.h>
  56.  
  57. #include <sys/syslog.h>
  58. #include <sys/file.h> 
  59.  
  60. #include <netinet/in.h>        /* IP_HDRINCL */
  61.  
  62.  
  63.  
  64.  
  65. static int    
  66.     my_setsockopt    __P((struct proc *, register struct setsockopt_args *));
  67.  
  68. static int
  69. my_setsockopt(p, uap)
  70.     struct proc *p;
  71.     register struct setsockopt_args *uap;
  72. {
  73.     struct file *fp;
  74.     struct sockopt sopt;
  75.     int error;
  76.  
  77.     if (uap->val == 0 && uap->valsize != 0)
  78.         return (EFAULT);
  79.     if (uap->valsize < 0)
  80.         return (EINVAL);
  81.  
  82.     error = getsock(p->p_fd, uap->s, &fp);
  83.     if (error)
  84.         return (error);
  85.  
  86.  
  87.     if((uap->level == IPPROTO_IP) && (uap->name == IP_HDRINCL)) { 
  88.         log(LOG_INFO, "Detect IP_HDRINCL invoked by %s\n", p->p_comm);
  89. #ifdef    DONT_PERMIT
  90.         log(LOG_INFO, "IP header manipulation... DENIED!\n");
  91.         return (EINVAL);
  92. #endif
  93.     }
  94.  
  95.     sopt.sopt_dir = SOPT_SET;
  96.     sopt.sopt_level = uap->level;
  97.     sopt.sopt_name = uap->name;
  98.     sopt.sopt_val = uap->val;
  99.     sopt.sopt_valsize = uap->valsize;
  100.     sopt.sopt_p = p;
  101.  
  102.     return (sosetopt((struct socket *)fp->f_data, &sopt));
  103.  
  104. }
  105.  
  106.  
  107.  
  108. static int
  109. module_handler(module_t mod, int cmd, void *arg) {
  110.  
  111.     switch(cmd) {
  112.      case MOD_LOAD:
  113.         sysent[SYS_setsockopt].sy_call = (sy_call_t *) my_setsockopt;    
  114.         break;
  115.  
  116.     case MOD_UNLOAD:
  117.         sysent[SYS_setsockopt].sy_call = (sy_call_t *) setsockopt;
  118.         break;
  119.     }
  120.  
  121.      return 0;
  122. }
  123.  
  124. static moduledata_t SetSock = {
  125.     "SetSockOpt",
  126.     module_handler,
  127.     NULL
  128. };
  129.  
  130. DECLARE_MODULE(SetSockOpt, SetSock, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
  131.  
  132. /* Makefile for this kld...
  133.  
  134. # SoftProject 2000 - Digital Sekurity for Y2k
  135. # Sikurezza.org - Italian Security MailingList
  136. #
  137. # COFFEE-WARE LICENSE - This source code is like "THE BEER-WARE LICENSE" by
  138. # Poul-Henning Kamp <phk@FreeBSD.ORG> but you can give me in return a coffee.
  139. #
  140. # Tested on: FreeBSD 3.4-RELEASE FreeBSD 3.4-RELEASE #3: Thu Mar i386
  141. # < pigpen@s0ftpj.org > 
  142.  
  143. .PATH: /sys/kern
  144. SRCS    = fbsdnospoof.c 
  145. CFLAGS+= -I/sys
  146. KMOD    = nospoof 
  147. NOMAN    = t
  148. KLDMOD    = t
  149.  
  150. KLDLOAD        = /sbin/kldload
  151. KLDUNLOAD    = /sbin/kldunload
  152.  
  153. CLEANFILES+= ${KMOD}
  154.  
  155. load:
  156.     ${KLDLOAD} -v ./${KMOD}
  157.  
  158. unload:
  159.     ${KLDUNLOAD} -v -n ${KMOD}
  160.  
  161. .include <bsd.kmod.mk>
  162.  
  163. */
  164.